layui.use(['form', 'element', 'jquery', 'button', 'popup'], function() {
    var form = layui.form;
    var element = layui.element;
    var button = layui.button;
    var popup = layui.popup;
    var $ = layui.jquery;

    // 登录过期的时候，跳出ifram框架
    if (top.location != self.location) top.location = self.location;

    // 登 录 提 交
    form.on('submit(login)', function(data) {
        var buttonLoad = button.load({
            elem: '.login'
        });
        $.ajax({
            url : '/admin/login/login',
            type : 'POST',
            data : data.field,
            success : function (ret) {
                if (ret.code == 1) {
                    popup.success("登录成功", function() {
                        location.href = "/admin/index/index"
                    });
                } else {
                    popup.failure(ret.msg, function () {
                        $('.code').val('');
                        $('.codeImage').trigger('click');
                    });
                }
                buttonLoad.stop(function () {});
            },
            done : function () {
                buttonLoad.stop(function () {});
            }
        });
        return false;
    });
});
